package org.ebyte;

import sootup.core.graph.StmtGraph;
import sootup.core.jimple.common.stmt.Stmt;
import sootup.core.signatures.MethodSignature;
import sootup.java.bytecode.inputlocation.JavaClassPathAnalysisInputLocation;
import sootup.java.core.JavaSootClass;
import sootup.java.core.JavaSootMethod;
import sootup.java.core.types.JavaClassType;
import sootup.java.core.views.JavaView;

import java.util.*;

/**
 * Hello world!
 */
public class App {

    public static void main(String[] args) {
        JavaClassPathAnalysisInputLocation input = new JavaClassPathAnalysisInputLocation(args[0]);
        JavaView view = new JavaView(input);
        System.out.println(view);

        JavaClassType classType = view.getIdentifierFactory().getClassType("demo");

        //JavaSootClass  :  represent a class
        JavaSootClass sootClass = view.getClass(classType).get();
        System.out.println(sootClass);


        MethodSignature methodSignature = view.getIdentifierFactory().getMethodSignature(
                classType,
                "div",
                "int",
                new ArrayList<String>() {{
                    add("int");
                    add("int");
                }}
        );
        JavaSootMethod method = view.getMethod(methodSignature).get();
        System.out.println(method.getSignature());

        StmtGraph<?> cfg = method.getBody().getStmtGraph();
        for (Stmt stmt : cfg.getStmts()) {
            System.out.println(stmt);
        }
    }
}
